VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "PPLA Lib Example"
   ClientHeight    =   1485
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   3885
   LinkTopic       =   "Form1"
   ScaleHeight     =   1485
   ScaleWidth      =   3885
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command1 
      Caption         =   "Print Label"
      Height          =   500
      Left            =   900
      TabIndex        =   0
      Top             =   400
      Width           =   2100
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
    Private Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
    End Type

    Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" _
            (ByVal lpPathName As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
            
    Const IMAGE_BITMAP = 0
    Const LR_LOADFROMFILE = &H10
    Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, _
            ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, _
            ByVal un2 As Long) As Long
    Private Declare Function DeleteObject Lib "Gdi32" (ByVal ho As Long) As Long
    Const szSavePath As String = "C:\Argox"
    Const szSaveFile As String = "C:\Argox\PPLA_Example.Prn"
    Const sznop1 As String = "nop_front" + vbCrLf
    Const sznop2 As String = "nop_middle" + vbCrLf
    Private Declare Function A_Bar2d_Maxi Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal primary As Long, ByVal secondary As Long, ByVal country As Long, _
            ByVal service As Long, ByVal mode As Byte, ByVal numeric As Long, ByVal data As String) As Long
    Private Declare Function A_Bar2d_Maxi_Ori Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Long, ByVal primary As Long, ByVal secondary As Long, ByVal country As Long, _
            ByVal service As Long, ByVal mode As Byte, ByVal numeric As Long, ByVal data As String) As Long
    Private Declare Function A_Bar2d_PDF417 Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal narrow As Long, ByVal width As Long, ByVal normal As Byte, ByVal security As Long, _
            ByVal aspect As Long, ByVal row As Long, ByVal column As Long, ByVal mode As Byte, _
            ByVal numeric As Long, ByVal data As String) As Long
    Private Declare Function A_Bar2d_PDF417_Ori Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Long, ByVal narrow As Long, ByVal width As Long, ByVal normal As Byte, _
            ByVal security As Long, ByVal aspect As Long, ByVal row As Long, ByVal column As Long, _
            ByVal mode As Byte, ByVal numeric As Long, ByVal data As String) As Long
    Private Declare Function A_Bar2d_DataMatrix Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal rotation As Long, ByVal hor_mul As Long, ByVal ver_mul As Long, ByVal ECC As Long, _
            ByVal data_format As Long, ByVal num_rows As Long, ByVal num_col As Long, _
            ByVal mode As Byte, ByVal numeric As Long, ByVal data As String) As Long
    Private Declare Sub A_Clear_Memory Lib "WINPPLA.DLL" ()
    Private Declare Sub A_ClosePrn Lib "WINPPLA.DLL" ()
    Private Declare Function A_CreatePrn Lib "WINPPLA.DLL" (ByVal selection As Long, _
            ByVal filename As String) As Long
    Private Declare Function A_Del_Graphic Lib "WINPPLA.DLL" (ByVal mem_mode As Long, _
            ByVal graphic As String) As Long
    Private Declare Function A_Draw_Box Lib "WINPPLA.DLL" (ByVal mode As Byte, ByVal x As Long, _
            ByVal y As Long, ByVal width As Long, ByVal height As Long, ByVal top As Long, _
            ByVal side As Long) As Long
    Private Declare Function A_Draw_Line Lib "WINPPLA.DLL" (ByVal mode As Byte, ByVal x As Long, _
            ByVal y As Long, ByVal width As Long, ByVal height As Long) As Long
    Private Declare Sub A_Feed_Label Lib "WINPPLA.DLL" ()
    Private Declare Function A_Get_DLL_Version Lib "WINPPLA.DLL" (ByVal nShowMessage As Long) As Long ' return point address.
    Private Declare Function A_Get_DLL_VersionA Lib "WINPPLA.DLL" (ByVal nShowMessage As Long) As Long
    Private Declare Function A_Get_Graphic Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal mem_mode As Long, ByVal format As Byte, ByVal filename As String) As Long
    Private Declare Function A_Get_Graphic_ColorBMP Lib "WINPPLA.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal mem_mode As Long, ByVal format As Byte, ByVal filename As String) As Long
    Private Declare Function A_Get_Graphic_ColorBMPEx Lib "WINPPLA.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
            ByVal rotate As Long, ByVal mem_mode As Long, ByVal format As Byte, _
            ByVal id_name As String, ByVal filename As String) As Long
    Private Declare Function A_Get_Graphic_ColorBMP_HBitmap Lib "WINPPLA.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
            ByVal rotate As Long, ByVal mem_mode As Long, ByVal format As Byte, _
            ByVal id_name As String, ByVal hbm As Long) As Long
    Private Declare Function A_Initial_Setting Lib "WINPPLA.DLL" (ByVal ttype As Long, _
            ByVal Source As String) As Long
    Private Declare Function A_WriteData Lib "WINPPLA.DLL" (ByVal IsImmediate As Long, _
            ByVal pbuf As String, ByVal length As Long) As Long
    Private Declare Function A_ReadData Lib "WINPPLA.DLL" (ByVal pbuf As String, ByVal length As Long, _
            ByVal dwTimeoutms As Long) As Long
    Private Declare Function A_Load_Graphic Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal Graphic_name As String) As Long
    Private Declare Function A_Open_ChineseFont Lib "WINPPLA.DLL" (ByVal path As String) As Long
    Private Declare Function A_Print_Form Lib "WINPPLA.DLL" (ByVal width As Long, _
            ByVal height As Long, ByVal copies As Long, ByVal amount As Long, _
            ByVal form_name As String) As Long
    Private Declare Function A_Print_Out Lib "WINPPLA.DLL" (ByVal width As Long, _
            ByVal height As Long, ByVal copies As Long, ByVal amount As Long) As Long
    Private Declare Function A_Prn_Barcode Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Long, ByVal typee As Byte, ByVal narrow As Long, ByVal width As Long, _
            ByVal height As Long, ByVal mode As Byte, ByVal numeric As Long, ByVal data As String) As Long
    Private Declare Function A_Prn_Text Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Long, ByVal font As Long, ByVal typee As Long, ByVal hor_factor As Long, _
            ByVal ver_factor As Long, ByVal mode As Byte, ByVal numeric As Long, _
            ByVal data As String) As Long
    Private Declare Function A_Prn_Text_Chinese Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal fonttype As Long, ByVal id_name As String, ByVal data As String, _
            ByVal mem_mode As Long) As Long
    Private Declare Function A_Prn_Text_TrueType Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal FSize As Long, ByVal FType As String, ByVal Fspin As Long, ByVal FWeight As Long, _
            ByVal FItalic As Long, ByVal FUnline As Long, ByVal FStrikeOut As Long, _
            ByVal id_name As String, ByVal data As String, ByVal mem_mode As Long) As Long
    Private Declare Function A_Prn_Text_TrueType_W Lib "WINPPLA.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal FHeight As Long, ByVal FWidth As Long, ByVal FType As String, _
            ByVal Fspin As Long, ByVal FWeight As Long, ByVal FItalic As Long, ByVal FUnline As Long, _
            ByVal FStrikeOut As Long, ByVal id_name As String, ByVal data As String, _
            ByVal mem_mode As Long) As Long
    Private Declare Function A_Set_Backfeed Lib "WINPPLA.DLL" (ByVal back As Long) As Long
    Private Declare Function A_Set_BMPSave Lib "WINPPLA.DLL" (ByVal nSave As Long, _
            ByVal pstrBMPFName As String) As Long
    Private Declare Function A_Set_Cutting Lib "WINPPLA.DLL" (ByVal cutting As Long) As Long
    Private Declare Function A_Set_Darkness Lib "WINPPLA.DLL" (ByVal darkness As Long) As Long
    Private Declare Function A_Set_DebugDialog Lib "WINPPLA.DLL" (ByVal nEnable As Long) As Long
    Private Declare Function A_Set_Feed Lib "WINPPLA.DLL" (ByVal rate As Byte) As Long
    Private Declare Function A_Set_Form Lib "WINPPLA.DLL" (ByVal formfile As String, _
            ByVal form_name As String, ByVal mem_mode As Long) As Long
    Private Declare Function A_Set_Margin Lib "WINPPLA.DLL" (ByVal position As Long, _
            ByVal margin As Long) As Long
    Private Declare Function A_Set_Prncomport Lib "WINPPLA.DLL" (ByVal baud As Long, _
            ByVal parity As Long, ByVal data As Long, ByVal sstop As Long) As Long
    Private Declare Function A_Set_Prncomport_PC Lib "WINPPLA.DLL" (ByVal nBaudRate As Long, _
            ByVal nByteSize As Long, ByVal nParity As Long, ByVal nStopBits As Long, _
            ByVal nDsr As Long, ByVal nCts As Long, ByVal nXonXoff As Long) As Long
    Private Declare Function A_Set_Sensor_Mode Lib "WINPPLA.DLL" (ByVal ttype As Byte, _
            ByVal continuous As Long) As Long
    Private Declare Function A_Set_Speed Lib "WINPPLA.DLL" (ByVal speed As Byte) As Long
    Private Declare Function A_Set_Syssetting Lib "WINPPLA.DLL" (ByVal transfer As Long, _
            ByVal cut_peel As Long, ByVal length As Long, ByVal zero As Long, ByVal pause As Long) As Long
    Private Declare Function A_Set_Unit Lib "WINPPLA.DLL" (ByVal unit As Byte) As Long
    Private Declare Function A_Set_Gap Lib "WINPPLA.DLL" (ByVal gap As Long) As Long
    Private Declare Function A_Set_Logic Lib "WINPPLA.DLL" (ByVal Logic As Long) As Long
    Private Declare Function A_Set_ProcessDlg Lib "WINPPLA.DLL" (ByVal nShow As Long) As Long
    Private Declare Function A_Set_ErrorDlg Lib "WINPPLA.DLL" (ByVal nShow As Long) As Long
    Private Declare Function A_Set_LabelVer Lib "WINPPLA.DLL" (ByVal centiInch As Long) As Long
    Private Declare Function A_GetUSBBufferLen Lib "WINPPLA.DLL" () As Long
    Private Declare Function A_EnumUSB Lib "WINPPLA.DLL" (ByVal buf As String) As Long
    Private Declare Function A_CreateUSBPort Lib "WINPPLA.DLL" (ByVal nPort As Long) As Long
    Private Declare Function A_CreatePort Lib "WINPPLA.DLL" (ByVal nPortType As Long, _
            ByVal nPort As Long, ByVal filename As String) As Long
    Private Declare Sub A_Clear_MemoryEx Lib "WINPPLA.DLL" (ByVal nMode As Long)
    Private Declare Sub A_Set_Mirror Lib "WINPPLA.DLL" ()
    Private Declare Function A_Bar2d_RSS Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Long, ByVal ratio As Long, ByVal height As Long, ByVal rtype As Byte, _
            ByVal mult As Long, ByVal seg As Long, ByVal data1 As String, ByVal data2 As String) As Long
    Private Declare Function A_Bar2d_QR_M Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Long, ByVal mult As Byte, ByVal value As Long, ByVal model As Long, _
            ByVal err As Byte, ByVal mask As Long, ByVal dinput As Byte, ByVal mode As Byte, _
            ByVal numeric As Long, ByVal data As String) As Long
    Private Declare Function A_Bar2d_QR_A Lib "WINPPLA.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Long, ByVal mult As Byte, ByVal value As Long, ByVal mode As Byte, _
            ByVal numeric As Long, ByVal data As String) As Long
    Private Declare Function A_GetNetPrinterBufferLen Lib "WINPPLA.DLL" () As Long
    Private Declare Function A_EnumNetPrinter Lib "WINPPLA.DLL" (ByVal buf As String) As Long
    Private Declare Function A_CreateNetPort Lib "WINPPLA.DLL" (ByVal nPort As Long) As Long
    'data is buffer address, so can use "ByVal data As Integer".
    Private Declare Function A_Prn_Text_TrueType_Uni Lib "WINPPLA.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal FSize As Long, ByVal FType As String, ByVal Fspin As Long, _
            ByVal FWeight As Long, ByVal FItalic As Long, ByVal FUnline As Long, _
            ByVal FStrikeOut As Long, ByVal id_name As String, ByRef data As Byte, _
            ByVal format As Long, ByVal mem_mode As Long) As Long
    'data is buffer address, so can use "ByVal data As Integer".
    Private Declare Function A_Prn_Text_TrueType_UniB Lib "WINPPLA.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal FSize As Long, ByVal FType As String, ByVal Fspin As Long, _
            ByVal FWeight As Long, ByVal FItalic As Long, ByVal FUnline As Long, _
            ByVal FStrikeOut As Long, ByVal id_name As String, ByRef data As Byte, _
            ByVal format As Long, ByVal mem_mode As Long) As Long
    Private Declare Function A_GetUSBDeviceInfo Lib "WINPPLA.DLL" (ByVal nPort As Long, _
            ByVal pDeviceName As String, ByRef pDeviceNameLen As Long, ByVal pDevicePath As String, _
            ByRef pDevicePathLen As Long) As Long
    Private Declare Function A_Set_EncryptionKey Lib "WINPPLA.DLL" (ByVal encryptionKey As String) As Long
    Private Declare Function A_Check_EncryptionKey Lib "WINPPLA.DLL" (ByVal decodeKey As String, _
            ByVal encryptionKey As String, ByVal dwTimeoutms As Long) As Long
    Private Declare Function A_Set_CommTimeout Lib "WINPPLA.DLL" (ByVal ReadTotalTimeoutConstant As Long, _
            ByVal WriteTotalTimeoutConstant As Long) As Long
    Private Declare Function A_Get_CommTimeout Lib "WINPPLA.DLL" (ByRef ReadTotalTimeoutConstant As Long, _
            ByRef WriteTotalTimeoutConstant As Long) As Long
    Private Declare Function A_Set_LabelForSmartPrint Lib "WINPPLA.DLL" (ByVal lablength As Long, _
            ByVal gaplength As Long) As Long

Private Sub Command1_Click()
        'Test code start
        ' open port.
        Dim nLen As Long
        Dim ret As Long
        Dim sw As Long
        Dim nVersion, nMainVersion, nSubVersion As Long
        Dim pbuf As String
        Dim strmsg As String
        pbuf = Space(128)
        ver = Space(128)

        ' dll version.
        nVersion = A_Get_DLL_VersionA(0)
        nMainVersion = Int(nVersion / 100)
        nSubVersion = nVersion Mod 100
        
        ' search port.
        nLen = A_GetUSBBufferLen() + 1
        strmsg = "DLL Ver: " + Str(nMainVersion) + "." + Str(nSubVersion) + vbCrLf  'only sample coding, not smart.
        If nLen > 1 Then
            Dim buf1 As String
            Dim buf2 As String
            Dim len1 As Long
            Dim len2 As Long
            len1 = 128
            len2 = 128
            buf1 = Space(len1)
            buf2 = Space(len2)
            Call A_EnumUSB(pbuf)
            Call A_GetUSBDeviceInfo(1, buf1, len1, buf2, len2)
            sw = 1
            If sw Then
                ret = A_CreatePrn(12, buf2) ' open usb.
            Else
                ret = A_CreateUSBPort(1) ' must call A_GetUSBBufferLen() function fisrt.
            End If
            If 0 < ret Then
                strmsg = strmsg + "Open USB fail!"
            Else
                strmsg = strmsg + "Open USB:" + vbCrLf + "Device name: "
                strmsg = strmsg + Left(buf1, len1)
                strmsg = strmsg + vbCrLf + "Device path: "
                strmsg = strmsg + Left(buf2, len2)
                'sw = 2
                If 2 = sw Then
                    'get printer status.
                    pbuf = Chr(1) + Chr(70) + vbCrLf
                    Call A_WriteData(1, pbuf, 4)   ' <SOH>F
                    ret = A_ReadData(pbuf, 2, 1000)
                End If
            End If
        Else
            Dim lpSA As SECURITY_ATTRIBUTES

            lpSA.nLength = Len(lpSA)
            ret = CreateDirectory(szSavePath, lpSA)
            ret = A_CreatePrn(0, szSaveFile) ' open file.
            strmsg = strmsg + "Open " + szSaveFile
            If 0 < ret Then
                strmsg = strmsg + " file fail!"
            Else
                strmsg = strmsg + " file succeed!"
            End If
        End If
        MsgBox (strmsg)
        If 0 < ret Then
            Exit Sub
        End If

        ' sample setting.
        Call A_Set_DebugDialog(1)
        Call A_Set_Unit(Asc("n"))
        Call A_Set_Syssetting(1, 0, 0, 0, 0)
        Call A_Set_Darkness(8)
        Call A_Del_Graphic(1, "*") ' delete all picture.
        Call A_Clear_Memory   ' clear memory.
        Call A_WriteData(0, sznop2, Len(sznop2))
        Call A_WriteData(1, sznop1, Len(sznop1))

        'draw box.
        Call A_Draw_Box(Asc("A"), 10, 10, 380, 280, 4, 4)
        Call A_Draw_Line(Asc("A"), 200, 10, 4, 280)

        'print text, true type text.
        Call A_Prn_Text(20, 30, 1, 2, 0, 1, 1, Asc("N"), 2, "PPLA Lib Example")
        Call A_Prn_Text_TrueType(20, 60, 30, "Arial", 1, 400, 0, 0, 0, "AA", "TrueType Font", 1) 'save in ram.
        Call A_Prn_Text_TrueType_W(20, 90, 20, 20, "Times New Roman", 1, 400, 0, 0, 0, "AB", "TT_W: 多字元測試", 1)
        ' When using standard label, and the printer is Intelli Print mode or Smart Print mode,
        ' When calling this function and giving the correct label information,
        ' the immediate print function will be enabled according to the label length setting.
        Call A_Set_LabelForSmartPrint(254 * 3, 30) ' label information: length= 3 * 25.4 mm, gap= 3 mm.
        
        Dim buff1(128) As Byte
        Dim buff2() As Byte
        Dim i As Integer
        buff2 = StrConv("TT_Uni: 多字元測試", vbNarrow) 'Converts UNICODE(wide characters) to single-byte characters.
        For i = LBound(buff2) To UBound(buff2)
            buff1(i) = buff2(i)
        Next i
        buff1(26) = 0 'null.
        buff1(27) = 0
        Call A_Prn_Text_TrueType_Uni(20, 120, 30, "Times New Roman", 1, 400, 0, 0, 0, "AC", buff1(0), 1, 1) 'UTF-16
        
        buff1(0) = 255 'UTF-16.
        buff1(1) = 254
        buff2 = StrConv("TT_UniB: 多字元測試", vbNarrow) 'Converts UNICODE(wide characters) to single-byte characters.
        For i = LBound(buff2) To UBound(buff2)
            buff1(i + 2) = buff2(i)
        Next i
        buff1(30) = 0 'null.
        buff1(31) = 0
        Call A_Prn_Text_TrueType_UniB(20, 150, 30, "Times New Roman", 1, 400, 0, 0, 0, "AD", buff1(0), 0, 1) 'Byte Order Mark.

        'barcode.
        Call A_Prn_Barcode(220, 60, 1, Asc("A"), 0, 0, 20, Asc("B"), 1, "1234")
        Call A_Bar2d_QR_A(220, 100, 1, Asc("3"), 10, Asc("N"), 0, "QR CODE")

        'picture.
        Call A_Get_Graphic_ColorBMP(220, 150, 1, Asc("B"), "bb.bmp") ' Color bmp file to ram.
        Call A_Get_Graphic_ColorBMPEx(220, 170, 200, 150, 2, 1, Asc("B"), "bb1", "bb.bmp") ' 180 angle.
        Dim himage As Long
        himage = LoadImage(0, "bb.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
        Call A_Get_Graphic_ColorBMP_HBitmap(300, 150, 250, 80, 1, 1, Asc("B"), "bb2", himage) ' 90 angle.
        If himage Then
            Call DeleteObject(himage)
        End If

        ' output.
        Call A_Print_Out(1, 1, 2, 1) ' copy 2.

        ' close port.
        Call A_ClosePrn
End Sub
